/*author:hexinglong   2014.04.22 系统管理模块页面处理 */
var warn_data;
var warn_chart;
var warn_option;

var money_data;
var money_chart;
var count_chart;
var money_option;
var count_option;


var Stat = {};
Stat.Warn = {
    //初始化，放入页面加载时需要初始化的数据
    init: function (path) {
    	//日历插件
       /* $("#warnDateBegin").datepicker({"showAnim":"blind","dateFormat":"yy-mm-dd",
    		onSelect:function(dateText,inst){	        			  
    			$("#warnDateEnd").datepicker("option","minDate",dateText);  
    		}
        });*/
        
        /*$("#warnDateEnd").datepicker({"showAnim":"blind","dateFormat":"yy-mm-dd",
    		onSelect:function(dateText,inst){	        			  
    			$("#warnDateBegin").datepicker("option","maxDate",dateText);  
    		}
        });*/
        //按钮事件绑定
    	require.config({
    	    paths:{ 
    	        'echarts':path+'script/echarts/echarts',
    	        'echarts/chart/bar' : path+'script/echarts/echarts-map',
    	        'echarts/chart/line': path+'script/echarts/echarts-map',
    	        'echarts/chart/pie' : path+'script/echarts/echarts-map'
    	    }
    	});
    	require(
    		    [
    		        'echarts',
    		        'echarts/chart/bar',
    		        'echarts/chart/line',
    		        'echarts/chart/pie'
    		    ],
    		    function(ec,t){
    		    	warn_chart = ec.init(document.getElementById("warnChart"));    		    	
    		    	Stat.Warn.print(path);           
    		    }
    		    
    	);
    	warn_data = $("#list").jqGrid({
            datatype: "local",
            colNames: ["分公司","总案件数", "黄色警告","红色警告", "黑色警告", "锁定", "黄色警告占比","红色警告占比", "黑色警告占比", "锁定占比"],
            colModel: [
                { name: "orgName"},
                { name: "caseCount"},
                { name: "yellowCount" },
                { name: "redCount" },
                { name: "blackCount"},
                { name: "lockCount"},
                { name: "yellowCountP",formatter:function(value){return value+"%";}},
                { name: "redCountP",formatter:function(value){return value+"%";}},
                { name: "blackCountP",formatter:function(value){return value+"%";}},
                { name: "lockCountP",formatter:function(value){return value+"%";}}
            ],
            shrinkToFit: true,
            autoencode: true,
            loadonce:true,
            autowidth: true,
            hidegrid: false,
            rownumbers: true
		});
    	warn_option ={
    		    tooltip : {
    		        trigger: 'item',
    		        formatter:function(a){
    		        	var str = a[1]+a[0]+a[2];
    		        	if(a[0].indexOf("占比")!=-1)
    		        		str +="%";
    		        	return str;
    		        }
    		    },
    		    toolbox: {
    		        show : true,
    		        feature : {
    		            restore : {show: true},
    		            saveAsImage : {show: true}
    		        }
    		    },
    		    calculable : true,
    		    legend: {
    		        data:['黄色警告','红色警告','黑色警告','锁定','黄色占比','红色占比','黑色占比','锁定占比'],
  
    		        padding: 1
    		    },
    		    xAxis : [
    		        {
    		            type : 'category'
    		        }
    		    ],
    		    yAxis : [
    		        {
    		            type : 'value',
    		            name : '数量(个)',
    		            axisLabel : {
    		                formatter: '{value} '
    		            }
    		        },
    		        {
    		            type : 'value',
    		            name : '案件占比(%)',
    		            axisLabel : {
    		                formatter: '{value}'
    		            }
    		        }
    		    ]
    		};
    	
    },
    print:function(path){
    	warn_chart.showLoading({
    	    text: '正在努力的读取数据中...',    //loading话术
    	});
    	var xData = new Array(),sData = new Array(),y = new Array(),r = new Array(),b = new Array(),l = new Array(),yp = new Array(),rp = new Array(),bp = new Array(),lp = new Array();
    	$.post(path+'stat/warn_stat.do', "beginDate="+$("#warnDateBegin").val()+"&endDate="+$("#warnDateEnd").val(), function (data) {
    		var str="[";
    		for(var name in data)
    		{
    			str += '{orgName:"'+data[name].orgName+'",yellowCount:'+data[name].yellowCount+
    			',redCount:'+data[name].redCount+',blackCount:'+data[name].blackCount+
    			',lockCount:'+data[name].lockCount+',yellowCountP:'+data[name].yellowCountP+
    			',redCountP:'+data[name].redCountP+',blackCountP:'+data[name].blackCountP+',lockCountP:'+data[name].lockCountP+'},';
    			xData.push(name);
    			y.push(data[name].yellowCount);
    			r.push(data[name].redCount);
    			b.push(data[name].blackCount);
    			l.push(data[name].lockCount);
    			yp.push(data[name].yellowCountP);
    			rp.push(data[name].redCountP);
    			bp.push(data[name].blackCountP);
    			lp.push(data[name].lockCountP);
    		}
    		if(str.length>1)
    			str = str.substring(0,str.length-1);
    		str+="]";
    		$("#list")[0].addJSONData(eval('('+str+')'));
    	
    		warn_option.xAxis =[
    		        {
    		            type : 'category',
    		            orient:'vertical',
    		            data:xData
    		        }
    		    ];
    		warn_option.series = [{
		   			 name: '黄色警告',                      
			         type: 'bar',                       
			         data: y
				},{
					 name: '红色警告',                       
			         type: 'bar',                       
			         data: r
				},{
					 name: '黑色警告',                    
			         type: 'bar',                     
			         data: b
				},{
					 name: '锁定',                        
			         type: 'bar',                       
			         data: l
				},{
					 name: '黄色占比',                     
			         type: 'line',
			         yAxisIndex: 1,
			         data: yp
				},{
					 name: '红色占比',                
			         type: 'line',
			         yAxisIndex: 1,
			         data: rp
				},{
					 name: '黑色占比',                     
			         type: 'line',
			         yAxisIndex: 1,
			         data: bp
				},{
					 name: '锁定占比',                 
			         type: 'line',
			         yAxisIndex: 1,
			         data: lp
				}];
    		warn_chart.setOption(warn_option);
    		
        });
    	warn_chart.hideLoading();
    },
    exportXls:function(){
    	 var url = "stat/warn_export.do?beginDate="+$("#warnDateBegin").val()+"&endDate="+$("#warnDateEnd").val();
	     window.top.location.href = url;
    }
};
Stat.Money = {
	    //初始化，放入页面加载时需要初始化的数据
	    init: function (path) {
	    	//日历插件
	        $("#moneyDateBegin").datepicker({"showAnim":"blind","dateFormat":"yy-mm-dd",
	    		onSelect:function(dateText,inst){	        			  
	    			$("#moneyDateEnd").datepicker("option","minDate",dateText);  
	    		}
	        });
	        
	        $("#moneyDateEnd").datepicker({"showAnim":"blind","dateFormat":"yy-mm-dd",
	    		onSelect:function(dateText,inst){	        			  
	    			$("#moneyDateBegin").datepicker("option","maxDate",dateText);  
	    		}
	        });
	        //按钮事件绑定
	    	require.config({
	    	    paths:{ 
	    	        'echarts':path+'script/echarts/echarts',
	    	        'echarts/chart/bar' : path+'script/echarts/echarts-map',
	    	        'echarts/chart/line': path+'script/echarts/echarts-map',
	    	        'echarts/chart/pie' : path+'script/echarts/echarts-map'
	    	    }
	    	});
	    	require(
	    		    [
	    		        'echarts',
	    		        'echarts/chart/bar',
	    		        'echarts/chart/line',
	    		        'echarts/chart/pie'
	    		    ],
	    		    function(ec,t){
	    		    	money_chart = ec.init(document.getElementById("moneyChart"));
	    		    	count_chart =  ec.init(document.getElementById("countChart")); 
	    		    	Stat.Money.print(path);           
	    		    }
	    		    
	    	);
	    	money_data = $("#list").jqGrid({
	            datatype: "local",
	            colNames: ["分公司","委案金额", "回款金额", "回款率","退案金额", "人均委案", "人均回款","人均回款率", "案件数量", "人均案件数量", "人均案件占比"],
	            colModel: [
	                { name: "orgName"},
	                { name: "caseCount"},
	                { name: "yellowCount" },
	                { name: "redCount" },
	                { name: "blackCount"},
	                { name: "lockCount"},
	                { name: "yellowCountP",formatter:function(value){return value+"%";}},
	                { name: "redCountP",formatter:function(value){return value+"%";}},
	                { name: "blackCountP",formatter:function(value){return value+"%";}},
	                { name: "blackCountP",formatter:function(value){return value+"%";}},
	                { name: "lockCountP",formatter:function(value){return value+"%";}}
	            ],
	            shrinkToFit: true,
	            autoencode: true,
	            loadonce:true,
	            autowidth: true,
	            hidegrid: false,
	            rownumbers: true
			});
	    	money_option ={
	    		    tooltip : {
	    		        trigger: 'item',
	    		        formatter:function(a){
	    		        	var str = a[1]+a[0]+a[2];
	    		        	if(a[0].indexOf("占比")!=-1)
	    		        		str +="%";
	    		        	return str;
	    		        }
	    		    },
	    		    toolbox: {
	    		        show : true,
	    		        feature : {
	    		            restore : {show: true},
	    		            saveAsImage : {show: true}
	    		        }
	    		    },
	    		    calculable : true,
	    		    legend: {
	    		        data:["分公司","委案金额", "回款金额", "回款率","退案金额", "人均委案", "人均回款","人均回款率"],
	    		    },
	    		    xAxis : [
	    		        {
	    		            type : 'category'
	    		        }
	    		    ],
	    		    yAxis : [
	    		        {
	    		            type : 'value',
	    		            name : '金额（元）',
	    		            axisLabel : {
	    		                formatter: '{value} '
	    		            }
	    		        },
	    		        {
	    		            type : 'value',
	    		            name : '案件占比(%)',
	    		            axisLabel : {
	    		                formatter: '{value}'
	    		            }
	    		        }
	    		    ]
	    		};
	    	
	    	
	    	count_option ={
	    		    tooltip : {
	    		        trigger: 'item',
	    		        formatter:function(a){
	    		        	var str = a[1]+a[0]+a[2];
	    		        	if(a[0].indexOf("占比")!=-1)
	    		        		str +="%";
	    		        	return str;
	    		        }
	    		    },
	    		    toolbox: {
	    		        show : true,
	    		        feature : {
	    		            restore : {show: true},
	    		            saveAsImage : {show: true}
	    		        }
	    		    },
	    		    calculable : true,
	    		    legend: {
	    		        data:["分公司","案件数量", "人均案件数量", "人均案件占比"],
	    		    },
	    		    xAxis : [
	    		        {
	    		            type : 'category'
	    		        }
	    		    ],
	    		    yAxis : [
	    		        {
	    		            type : 'value',
	    		            name : '数量(个)',
	    		            axisLabel : {
	    		                formatter: '{value} '
	    		            }
	    		        },
	    		        {
	    		            type : 'value',
	    		            name : '案件占比(%)',
	    		            axisLabel : {
	    		                formatter: '{value}'
	    		            }
	    		        }
	    		    ]
	    		};
	    	
	    },
	    print:function(path){
	    	money_chart.showLoading({
	    	    text: '正在努力的读取数据中...',    //loading话术
	    	});
	    	var xData = new Array(),sData = new Array(),y = new Array(),r = new Array(),b = new Array(),l = new Array(),yp = new Array(),rp = new Array(),bp = new Array(),lp = new Array();
	    	$.post(path+'stat/warn_stat.do', "beginDate="+$("#moneyDateBegin").val()+"&endDate="+$("#moneyDateEnd").val(), function (data) {
	    		var str="[";
	    		for(var name in data)
	    		{
	    			str += '{orgName:"'+data[name].orgName+'",yellowCount:'+data[name].yellowCount+
	    			',redCount:'+data[name].redCount+',blackCount:'+data[name].blackCount+
	    			',lockCount:'+data[name].lockCount+',yellowCountP:'+data[name].yellowCountP+
	    			',redCountP:'+data[name].redCountP+',blackCountP:'+data[name].blackCountP+',lockCountP:'+data[name].lockCountP+'},';
	    			xData.push(name);
	    			y.push(data[name].yellowCount);
	    			r.push(data[name].redCount);
	    			b.push(data[name].blackCount);
	    			l.push(data[name].lockCount);
	    			yp.push(data[name].yellowCountP);
	    			rp.push(data[name].redCountP);
	    			bp.push(data[name].blackCountP);
	    			lp.push(data[name].lockCountP);
	    		}
	    		if(str.length>1)
	    			str = str.substring(0,str.length-1);
	    		str+="]";
	    		$("#list")[0].addJSONData(eval('('+str+')'));
	    	
	    		money_option.xAxis =[
	    			    		        {
	    			    		            type : 'category',
	    			    		            data:xData
	    			    		        }
	    			    		    ];
	    			    		money_option.series = [{
	    					   			 name: '黄色警告',                      
	    						         type: 'bar',                       
	    						         data: y
	    							},{
	    								 name: '红色警告',                       
	    						         type: 'bar',                       
	    						         data: r
	    							},{
	    								 name: '黑色警告',                    
	    						         type: 'bar',                     
	    						         data: b
	    							},{
	    								 name: '锁定',                        
	    						         type: 'bar',                       
	    						         data: l
	    							},{
	    								 name: '黄色占比',                     
	    						         type: 'line',
	    						         yAxisIndex: 1,
	    						         data: yp
	    							},{
	    								 name: '红色占比',                
	    						         type: 'line',
	    						         yAxisIndex: 1,
	    						         data: rp
	    							},{
	    								 name: '黑色占比',                     
	    						         type: 'line',
	    						         yAxisIndex: 1,
	    						         data: bp
	    							},{
	    								 name: '锁定占比',                 
	    						         type: 'line',
	    						         yAxisIndex: 1,
	    						         data: lp
	    							}];
	    			    		count_option.xAxis =[
	    			    			    		        {
	    			    			    		            type : 'category',
	    			    			    		            data:xData
	    			    			    		        }
	    			    			    		    ];
	    			    			    		count_option.series = [{
	    			    					   			 name: '黄色警告',                      
	    			    						         type: 'bar',                       
	    			    						         data: y
	    			    							},{
	    			    								 name: '红色警告',                       
	    			    						         type: 'bar',                       
	    			    						         data: r
	    			    							},{
	    			    								 name: '黑色警告',                    
	    			    						         type: 'bar',                     
	    			    						         data: b
	    			    							},{
	    			    								 name: '锁定',                        
	    			    						         type: 'bar',                       
	    			    						         data: l
	    			    							},{
	    			    								 name: '黄色占比',                     
	    			    						         type: 'line',
	    			    						         yAxisIndex: 1,
	    			    						         data: yp
	    			    							},{
	    			    								 name: '红色占比',                
	    			    						         type: 'line',
	    			    						         yAxisIndex: 1,
	    			    						         data: rp
	    			    							},{
	    			    								 name: '黑色占比',                     
	    			    						         type: 'line',
	    			    						         yAxisIndex: 1,
	    			    						         data: bp
	    			    							},{
	    			    								 name: '锁定占比',                 
	    			    						         type: 'line',
	    			    						         yAxisIndex: 1,
	    			    						         data: lp
	    			    							}];
	    		money_chart.setOption(money_option);
	    		count_chart.setOption(count_option);
	    		
	        });
	    	money_chart.hideLoading();
	    },
	    exportXls:function(){
	    	 var url = "stat/money_export.do?beginDate="+$("#moneyDateBegin").val()+"&endDate="+$("#moneyDateEnd").val();
		     window.top.location.href = url;
	    }
	};

